
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, 2012 and Azure
-- --------------------------------------------------
-- Date Created: 12/02/2013 19:53:42
-- Generated from EDMX file: C:\TFS Projects\squadwuschel\DiTemplates\MVC\UserManagement\User.EF.Model\MainModel.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [IoC];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_MemberMemberExtension]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[MemberExtensionSet] DROP CONSTRAINT [FK_MemberMemberExtension];
GO
IF OBJECT_ID(N'[dbo].[FK_MemberMemberRights]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[MemberRightsSet] DROP CONSTRAINT [FK_MemberMemberRights];
GO
IF OBJECT_ID(N'[dbo].[FK_MemberMemberOAuth]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[MemberOAuth] DROP CONSTRAINT [FK_MemberMemberOAuth];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[MemberSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[MemberSet];
GO
IF OBJECT_ID(N'[dbo].[MemberExtensionSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[MemberExtensionSet];
GO
IF OBJECT_ID(N'[dbo].[MemberOAuth]', 'U') IS NOT NULL
    DROP TABLE [dbo].[MemberOAuth];
GO
IF OBJECT_ID(N'[dbo].[MemberRightsSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[MemberRightsSet];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'MemberSet'
CREATE TABLE [dbo].[MemberSet] (
    [Id] bigint IDENTITY(1,1) NOT NULL,
    [Username] nvarchar(max)  NOT NULL,
    [Password] nvarchar(max)  NOT NULL,
    [CreationDate] datetime  NOT NULL,
    [PasswordCheangedDate] datetime  NOT NULL,
    [PasswordSalt] nvarchar(max)  NOT NULL,
    [PasswordVerificationToken] nvarchar(max)  NOT NULL,
    [PasswordVerifivationTokenExpirationDate] datetime  NOT NULL,
    [LoginTries] int  NOT NULL,
    [LastLoginTry] datetime  NOT NULL,
    [IsActive] bit  NOT NULL
);
GO

-- Creating table 'MemberExtensionSet'
CREATE TABLE [dbo].[MemberExtensionSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Firstname] nvarchar(max)  NOT NULL,
    [Lastname] nvarchar(max)  NOT NULL,
    [Mobilenumber] nvarchar(max)  NOT NULL,
    [Title] int  NOT NULL,
    [Member_Id] bigint  NOT NULL
);
GO

-- Creating table 'MemberOAuth'
CREATE TABLE [dbo].[MemberOAuth] (
    [Provider] nvarchar(30)  NOT NULL,
    [ProviderUserId] nvarchar(100)  NOT NULL,
    [ProviderUsername] nvarchar(max)  NOT NULL,
    [MemberId] bigint  NOT NULL,
    [Member_Id] bigint  NOT NULL
);
GO

-- Creating table 'MemberRightsSet'
CREATE TABLE [dbo].[MemberRightsSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [MemberRight] int  NOT NULL,
    [MemberId] bigint  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'MemberSet'
ALTER TABLE [dbo].[MemberSet]
ADD CONSTRAINT [PK_MemberSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'MemberExtensionSet'
ALTER TABLE [dbo].[MemberExtensionSet]
ADD CONSTRAINT [PK_MemberExtensionSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Provider], [ProviderUserId] in table 'MemberOAuth'
ALTER TABLE [dbo].[MemberOAuth]
ADD CONSTRAINT [PK_MemberOAuth]
    PRIMARY KEY CLUSTERED ([Provider], [ProviderUserId] ASC);
GO

-- Creating primary key on [Id] in table 'MemberRightsSet'
ALTER TABLE [dbo].[MemberRightsSet]
ADD CONSTRAINT [PK_MemberRightsSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [Member_Id] in table 'MemberExtensionSet'
ALTER TABLE [dbo].[MemberExtensionSet]
ADD CONSTRAINT [FK_MemberMemberExtension]
    FOREIGN KEY ([Member_Id])
    REFERENCES [dbo].[MemberSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_MemberMemberExtension'
CREATE INDEX [IX_FK_MemberMemberExtension]
ON [dbo].[MemberExtensionSet]
    ([Member_Id]);
GO

-- Creating foreign key on [MemberId] in table 'MemberRightsSet'
ALTER TABLE [dbo].[MemberRightsSet]
ADD CONSTRAINT [FK_MemberMemberRights]
    FOREIGN KEY ([MemberId])
    REFERENCES [dbo].[MemberSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_MemberMemberRights'
CREATE INDEX [IX_FK_MemberMemberRights]
ON [dbo].[MemberRightsSet]
    ([MemberId]);
GO

-- Creating foreign key on [Member_Id] in table 'MemberOAuth'
ALTER TABLE [dbo].[MemberOAuth]
ADD CONSTRAINT [FK_MemberMemberOAuth]
    FOREIGN KEY ([Member_Id])
    REFERENCES [dbo].[MemberSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_MemberMemberOAuth'
CREATE INDEX [IX_FK_MemberMemberOAuth]
ON [dbo].[MemberOAuth]
    ([Member_Id]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------